<?php

namespace App\Http\Controllers\Admin;

use App\Home\Special;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use App\Model\RTResult;
class SpecialController extends Controller
{
   //专辑列表分页
    public function special()
    {
        $data=DB::table('users')->rightJoin('specials','specials.user_id','=','users.id')->paginate(2);
        return view('admin.special.special')->with('data',$data);
    }
//    多条件查询
    public function specialdata(Request $request)
    {
//        获取查询条件
        $username = isset($request->username) ? $request->username : '';
        $tag = isset($request->tag) ? $request->tag : '';
        $where=1;
//        拼接查询条件
        if ($username != '') {
            $where .="   and username like '%{$username}%'";
        }
        if ($tag != '') {
            $where .="   and tag like '%{$tag}%'";
        }
//查询并且分页
        $data=DB::table('specials')->leftJoin('users','specials.user_id','=','users.id')
                    ->whereRaw($where)
                  ->paginate(1);
        return view('admin.special.special')->with('data',$data);
    }
    //修改专辑的权限
    public function changeban(Request $request)
    {
        $input = $request->all();
        $special = Special::find($input['id']);
        $special->ban=($special->ban==1?2:1);
        $res = $special->save();
        if($res){
            $data = [
                'status'=>0,
                'msg'=>'亲，展示权限更新成功喽^*^',
            ];
        }else{
            $data = [
                'status'=>1,
                'msg'=>'展示权限更新失败，请重试',
            ];
        }
        return $data;
    }

}
